// NOTE: compile with g++ filename.cpp -std=c++11
#include "painter.h"

void pixel_write(int, int);
void pixel_write(int i, int j, painter_ptr painter, FILE *fp)
{
    static unsigned char color[3];
    color[0] = painter->RD(i, j) & 255;
    color[1] = painter->GR(i, j) & 255;
    color[2] = painter->BL(i, j) & 255;
    fwrite(color, 1, 3, fp);
}

int main()
{
    for (auto &it : getPainterPtr())
    {
        painter_ptr painter = it;

        if (nullptr == painter)
            continue;

        // std::thread t([&]() {
        FILE *fp = fopen(painter->NAME(), "wb");
        std::cout << painter->NAME() << std::endl;
        fprintf(fp, "P6\n%d %d\n255\n", DIM, DIM);
// #pragma omp parallel for
        for (int j = 0; j < DIM; j++)
            for (int i = 0; i < DIM; i++)
                pixel_write(i, j, painter, fp);

        fclose(fp);
        // });
    }

    return 0;
}
